<template>
  <div>
    <v-indexTop></v-indexTop>
    <div class="rsm-main">
      <div class="r-h2">
        <h1>欢迎来到超聘</h1>
        <span>快速完善简历，理想职位又进一步</span>
      </div>

      <div class="rsm-model">
        <el-form ref="forms" :model="forms" :rules="rules" label-width="80px">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="forms.name"></el-input>
          </el-form-item>
          <el-form-item label="性别" prop="gender">
            <el-radio-group v-model="forms.gender">
              <el-radio label="男" border>男性</el-radio>
              <el-radio label="女" border>女性</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="邮箱" prop="email">
            <el-input placeholder="请输入内容" v-model="forms.email" clearable>
            </el-input>
          </el-form-item>
          <el-form-item label="出生日期" prop="birth_date">
            <el-date-picker
              v-model="forms.birth_date"
              type="date"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="所在城市" prop="city">
            <el-input placeholder="请输入内容" v-model="forms.city" clearable>
            </el-input>
          </el-form-item>
          <el-form-item label="求职身份" prop="identity">
            <el-radio-group v-model="forms.identity" @change="checkIdentity">
              <el-radio-button label="我是职场人"></el-radio-button>
              <el-radio-button label="我是学生"></el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="求职状态" prop="state">
            <el-select
              v-model="forms.state"
              placeholder="请选择"
              v-if="forms.identity == '我是职场人'"
            >
              <el-option
                v-for="item in forms.options"
                :key="item.value"
                :label="item.label"
                :value="item.label"
              >
              </el-option>
            </el-select>
            <el-select v-model="forms.state" placeholder="请选择" v-else>
              <el-option
                v-for="item in forms.options1"
                :key="item.value"
                :label="item.label"
                :value="item.label"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>

          </el-form-item>
          <el-form-item class="tijiao">
            <el-button type="primary" @click="submitForm('forms')"
              >&nbsp;&nbsp;下&nbsp;&nbsp;一&nbsp;&nbsp;步&nbsp;&nbsp;</el-button
            >
            <el-button type="primary" @click="resetForm('forms')"
              >&nbsp;&nbsp;重&nbsp;&nbsp;置&nbsp;&nbsp;</el-button
            >
          </el-form-item>
        </el-form>
        <!-- <el-button type="primary" @click="next_page"
            >&nbsp;&nbsp;下&nbsp;&nbsp;一&nbsp;&nbsp;步&nbsp;&nbsp;></el-button
          > -->
      </div>
    </div>
  </div>
</template>

<script>
import indexTop from "../assemblyPublic/Index-top";
export default {
  watch:{

  },
  data() {
    return {
      forms: {
        name: "", //姓名
        gender: "", //性别
        birth_date: "", //出生日期
        email: "", //邮箱
        identity: "", //身份
        city: "", //城市
        state: "", //状态
        begin_date: "", //工作开始时间
        options: [
          {
            value: "ss_1",
            label: "在职，看看新机会",
          },
          {
            value: "ss_2",
            label: "在职，急需职位",
          },
          {
            value: "ss_3",
            label: "离职，寻找工作",
          },
        ],
        options1: [
          {
            value: "s_c_1",
            label: "在校，寻找实习岗位",
          },
          {
            value: "s_c_2",
            label: "离校，急需工作",
          },
        ],
      },
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
          { min: 3, max: 8, message: "长度在 3 到 8 个字符", trigger: "blur" },
        ],
        gender: [{ required: true, message: "必选项", trigger: "change" }],
        birth_date: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
        email: [
          {required:true,
            validator: (rule, value, callback) => {
              if (!value) {
                callback(new Error("邮箱不能为空"));
              } else {
                const reg = /^([a-zA-Z\d])(\w|\-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,4}$/;
                console.log(reg.test(value));
                if (reg.test(value)) {
                  callback();
                } else {
                  callback(new Error("请输入正确的邮箱"));
                }
              }
            },
            trigger: "blur",
          },
        ],
        identity:[
          {required:true,message:"必选项",trigger:"change"}
        ],
        city: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        state:[
          {required:true,message:"必选项",trigger:"blur"}
        ]
      },
    };
  },
  methods: {
    submitForm(formsName) {
      this.$refs[formsName].validate((valid) => {
        if (valid) {
          this.$axios({
            method: "POST",
            url: "api/register",
            data: this.forms,
          })
          .then((result) => {
              console.log(result.data);
              //学生
            if (result.data.register_case == "ok0") {
               this.$router.push({
                path: "../resumeEducationPage",
                query:{
                  u_type:true,
                }
              });
            }//社会人士
            if (result.data.register_case == "ok1") {
               this.$router.push({
                path: "../resumeExperience",
                query:{
                  u_type:false,
                }
              });
            }
            if (result.data.register_case == "no") {
                console.log("error submit!!");
                alert('数据有误！！')
                return false;
            }
          })
        .catch((err) => {
          console.log(err);
        });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    checkIdentity(){
      this.forms.state = ''
    }
  },
  components: {
    "v-indexTop": indexTop,
  },
};
</script>
<style>
.rsm-main {
  width: 60%;
  background: rgb(253, 253, 253);
  margin: 50px auto;
  padding: 30px 0px;
  border: 1px solid rgb(202, 202, 202);
}
.rsm-model .el-form-item {
  width: 48%;
  display: inline-block;
  margin-bottom: 50px;
}
.rsm-model .el-form-item__label {
  text-align: left;
}
.rsm-model .el-input__inner {
  width: 80%;
}
.rsm-model .el-radio.is-bordered {
  width: 35%;
}
.rsm-model .el-form {
  margin-top: 10%;
  text-align: left;
}
.rsm-model .tijiao {
  margin-top: 10%;
  float: right;
}
.r-h2 {
  width: 250px;
  float: left;
  margin-left: 5%;
  text-align: left;
}
.r-h2 span {
  color: rgb(184, 184, 189);
  font-size: 16px;
}

.rsm-model {
  width: 90%;
  height: 580px;
  margin: 0px auto;
  margin-top: 70px;
}
.rsm-model ul {
  width: 100%;
  background: rgb(87, 25, 145);
  text-align: left;
  font-size: 18px;
}
.rsm-model ul li {
  width: 50%;
  height: 100px;
  float: left;
  margin-top: 20px;
  color: rgb(76, 77, 78);
}
.rsm-model ul li p {
  margin-top: 10px;
  margin-bottom: 10px;
  padding-left: 3px;
}
.next-p {
  width: 100px;
  float: right;
  margin-right: 55px;
  margin-top: 30px;
}
</style>
